#!/usr/bin/python
# -*- coding: cp1250 -*-

import os
import re
import sys
import time
import string
import pepe.p_oslevel.basic as osb

fw_slash = lambda x: re.sub(r'\\', '/', x)

# time now
tn = lambda : time.strftime ("%Y%m%dT%H%M%S", time.localtime())

if __name__ == "__main__":
    ''' 
    app launch wrapper utility

    : OS independent do not use win32
    : is equivalent to windoze variant
        @echo off
        echo %date% %time% %1 %2 %3 %4 %5 %6 %7
        %1 %2 %3 %4 %5 %6 %7
    '''
    path = fw_slash(osb.wai())

    if  len(sys.argv) == 2:
        inpf = path + sys.argv[1]
        ifna = os.path.split(inpf)[1]
        print tn(), ifna
        os.system(string.join(sys.argv[1:], ' '))
        print tn()

    if  len(sys.argv) == 3:
        inpf = path + sys.argv[2]
        ifna = os.path.split(inpf)[1]
        print tn(), ifna
        os.system(string.join(sys.argv[1:], ' '))
        print tn()

    if  len(sys.argv) not in (2,3):
        sys.stderr.write('usage: r <app-to-run and-parameters>')
